*****************************************************************
* Replication directory for                                   ***
* Prime locations                                             ***
* by Gabriel M. Ahlfeldt, Thilo N.H. Albers, Kristian Behrens ***
* Published in American Economic Review: Insights             ***
*****************************************************************
* 01/2025
* Stata
version 17.0

* This do file tablulates big data establishments by type

* Load data 
	u "$data_125cities/CLUSTERING/RAW/primepoints_includingHQs.dta", clear
	
* Tabulate big data establishment from Google Places	
	tab type_globa if global_com  == 0
	keep if global_com  == 0
	gen one = 1
	collapse (sum) Establishments = one, by(type_globa)
	label var type "Type of Firm"
	label var Establishments "Establishments"
* Write Appendix Table A.2.1.	
	capture mkdir "$tables_App/GlobalCities"
	texsave * using "$tables_App/GlobalCities/TAB_A2_1_Establishments.tex", title("Prime Service Establishments by Industry") size("footnotesize")   width(10cm) align(lc)  varlabels replace  frag  footnote(".") 		
	
* Load data 
	u "$data_125cities/CLUSTERING/RAW/primepoints_includingHQs.dta", clear	
	
* Tabulate manually scraped establishments by industry
	tab type_globa if global_com  == 1
	keep if global_com  == 1
	gen one = 1
	collapse (sum) Establishments = one, by(type_globa)
	label var type "Type"
	label var Establishments "Establishments"
	sum Establishments
	gen Share = Establishments / r(sum) * 100
	tostring Share, replace force format(%9.1fc)
	label var Share "Share"
* Write Appendix Table A.2.2.	
	capture mkdir "$tables_App/GlobalCities"
	texsave * using "$tables_App/GlobalCities/TAB_A2_2_Establishments.tex", title("Global Prime Service Establishments by Industry") size("footnotesize")   width(10cm) align(lc)  varlabels replace  frag  footnote(".") 
	
	
* Tabulate `global establishments' by company

* Load data 
	u "$data_125cities/CLUSTERING/RAW/primepoints_global_CompanyNames.dta", clear	
	
* Tabulate manually scraped establishments	
	drop if TYPE_GLOBAL_PRIME_ESTABLISHMENT=="StockExchange"
	drop if TYPE_GLOBAL_PRIME_ESTABLISHMENT=="TS HQ"
	drop if TYPE_GLOBAL_PRIME_ESTABLISHMENT=="Central Bank"
	
	sort TYPE_GLOBAL_PRIME_ESTABLISHMENT Company

	gen one = 1
	collapse (sum) Establishments = one (first) TYPE_GLOBAL_PRIME_ESTABLISHMENT , by(Company)
	
	ren Establishments N 
	gen Source="Company's website (" + TYPE_GLOBAL_PRIME_ESTABLISHMENT + ")"
	gen Coordinates="X" if inlist(Company,"KPMG", "BCG","McKinsey","Bain","Kirkland","BakerMcKenzie","DLAPiper")
	replace Coordinates="X" if inlist(Company,"Skadden","CliffordChance","SidleyAustin","AllenOvery","Axa","Allianz")
	replace Coordinates="X" if inlist(Company,"PrudentialFinancial","JPMorgan","Goldman","MerillLynch","MorganStanley","Barclays","DeutscheBank","WellsFargo")
	gen Address="X" if Coordinates==""
	
	sort TYPE_GLOBAL_PRIME_ESTABLISHMENT Company
	order Company Source N Coordinates Address
	keep Company Source N Coordinates Address
	texsave * using "$tables_App/GlobalCities/TAB_A2_3_EstablishmentsCompanies.tex", title("Global Prime Service Companies and Establishments") size("footnotesize")   width(10cm) align(lc)  varlabels replace  frag  footnote(".") 
	
	
	
	
* Script ends
